macro 'make ROI inside 1300*1000 [X]';
begin
MakeRoi(1,1,1298,998);
end;


macro 'paste histo 256*148 [Y]';
begin
MakeRoi(1318,100,256,148);
Paste;
DrawBoundary;
end;


macro 'make ROI for histo 256*148';
begin
MakeRoi(1318,100,256,148);
end;


macro 'make ROI upper right [Z]';
begin
MakeRoi(1300,0,300,840);
end; 


macro 'make ROI left [L]';
begin
MakeRoi(0,0,1300,1000);
end; 


macro 'import 1300*1000';
begin
SetCustom(1300,1000,0);
Import('image');
end;

macro 'import raw image [0]';
var
w,h:   integer;
begin
w:= GetNumber('width: ',1200);
h:= GetNumber('height: ',1000);
SetImport('Custom');
SetCustom(w,h,0);
Import('image');
end;

macro '(-' begin end;




macro 'ROT to opt.+ LUT [+]';
var
  n,mean,mode,min,max: integer;
  i,j,l,inc,ninc:integer;
begin
   PutMessage('To adapt LUT to histogram, select region first');
   Measure;
   GetResults(n,mean,mode,min,max);
   ninc:=(max-min-2)/2;
   inc:=256/ninc;
  for j:=1 to ninc do begin
    i:=2*j;
    l:=j+min;
    RedLUT[l]:=255;
    GreenLUT[l]:=255-i;
    BlueLUT[l]:=i;
  end;
  for j:=1 to ninc do begin
    i:=2*j;
    l:=j+min+ninc;
    RedLUT[l]:=255-i;
    GreenLUT[l]:=i;
    BlueLUT[l]:=255;
  end;
  UpdateLUT;
end;


macro 'ROT to opt.- LUT [-]';
var
  n,mean,mode,min,max: integer;
  i,j,l,inc,ninc:integer;
begin
   PutMessage('To adapt LUT to histogram, select region first');
   Measure;
   GetResults(n,mean,mode,min,max);
   ninc:=(max-min-2)/2;
   inc:=256/ninc;
  for j:=1 to ninc do begin
    i:=2*j;
    l:=j+min;
    RedLUT[l]:=i;
    GreenLUT[l]:=255-i;
    BlueLUT[l]:=255;
  end;
  for j:=1 to ninc do begin
    i:=2*j;
    l:=j+min+ninc;
    RedLUT[l]:=255;
    GreenLUT[l]:=i;
    BlueLUT[l]:=255-i;
  end;
  UpdateLUT;
end;


macro 'ROT000 to crossPol LUT [P]';
var
  n,mean,mode,min,max: integer;
  i,j,l,v,inc,ninc:integer;
  gamma,sin2:real
begin
   PutMessage('To adapt LUT to histogram, select region first');

  Measure;
  GetResults(n,mean,mode,min,max);
  min:=GetNumber('min:',min);
  max:=GetNumber('max:',max);
  gamma:=GetNumber('Gamma(0.1-3.0):',2);

  for i:=1 to 254 DO begin
    if (i>min) and (i<max)
      then v:=exp(gamma*ln((i-min)/(max-min)))*255 {x^y=exp(y*ln(x)}
      else begin
        if i<=min then v:=0 else v:=255;
      end;
    RedLUT[i]:=255-v;
    GreenLUT[i]:=255-v;
    BlueLUT[i]:=255-v;
  end;
  UpdateLUT;
  ApplyLUT;

  Measure;
  GetResults(n,mean,mode,min,max);
  min:=GetNumber('min:',min);
  max:=GetNumber('max:',max);

  for i:=1 to min do begin
    RedLUT[i]:=0;
    GreenLUT[i]:=0;
    BlueLUT[i]:=0;
  end;

  for j:=min to max DO begin
    i:=j-min;
    sin2:=sin(i*0.01745*180/(max-min));
    v:=round(sin2*255);
    RedLUT[j]:=(255-v);
    GreenLUT[j]:=(255-v);
    BlueLUT[j]:=(255-v);
  end;

  for i:=max to 255 do begin
    RedLUT[i]:=0;
    GreenLUT[i]:=0;
    BlueLUT[i]:=0;
  end;

  UpdateLUT;
END;


macro '(-' begin end;


macro 'INC strips [A]';
var
  i,j,l:integer;
begin
  for i:=1 to 10 do begin
    j:=i;
    RedLUT[j]:=50;
    GreenLUT[j]:=0;
    BlueLUT[j]:=120;
  end;
  for i:=1 to 10 do begin
    j:=i+10;
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=208;
  end;
  for i:=1 to 10 do begin
    j:=i+20;
    RedLUT[j]:=0;
    GreenLUT[j]:=10;
    BlueLUT[j]:=250;
  end;
  for i:=1 to 10 do begin
    j:=i+30;
    RedLUT[j]:=0;
    GreenLUT[j]:=95;
    BlueLUT[j]:=240;
  end;
  for i:=1 to 10 do begin
    j:=i+40;
    RedLUT[j]:=0;
    GreenLUT[j]:=133;
    BlueLUT[j]:=158;
  end;
  for i:=1 to 10 do begin
    j:=i+50;
    RedLUT[j]:=0;
    GreenLUT[j]:=148;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+60;
    RedLUT[j]:=0;
    GreenLUT[j]:=198;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+70;
    RedLUT[j]:=10;
    GreenLUT[j]:=230;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+80;
    RedLUT[j]:=100;
    GreenLUT[j]:=240;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+90;
    RedLUT[j]:=198;
    GreenLUT[j]:=240;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+100;
    RedLUT[j]:=240;
    GreenLUT[j]:=240;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+110;
    RedLUT[j]:=250;
    GreenLUT[j]:=220;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+120;
    RedLUT[j]:=240;
    GreenLUT[j]:=200;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+130;
    RedLUT[j]:=240;
    GreenLUT[j]:=180;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+140;
    RedLUT[j]:=240;
    GreenLUT[j]:=140;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+150;
    RedLUT[j]:=240;
    GreenLUT[j]:=100;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+160;
    RedLUT[j]:=240;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
  for j:=171 to 180 do begin
    RedLUT[j]:=150;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
  for j:=181 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;

  UpdateLUT;
end;


macro 'INC strips 10 black[B]';
var
  i,j,l:integer;
begin
  for i:=1 to 10 do begin
    j:=i;
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+10;
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=208;
  end;
  for i:=1 to 10 do begin
    j:=i+20;
    RedLUT[j]:=0;
    GreenLUT[j]:=10;
    BlueLUT[j]:=250;
  end;
  for i:=1 to 10 do begin
    j:=i+30;
    RedLUT[j]:=0;
    GreenLUT[j]:=95;
    BlueLUT[j]:=240;
  end;
  for i:=1 to 10 do begin
    j:=i+40;
    RedLUT[j]:=0;
    GreenLUT[j]:=133;
    BlueLUT[j]:=158;
  end;
  for i:=1 to 10 do begin
    j:=i+50;
    RedLUT[j]:=0;
    GreenLUT[j]:=148;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+60;
    RedLUT[j]:=0;
    GreenLUT[j]:=198;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+70;
    RedLUT[j]:=10;
    GreenLUT[j]:=230;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+80;
    RedLUT[j]:=100;
    GreenLUT[j]:=240;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+90;
    RedLUT[j]:=198;
    GreenLUT[j]:=240;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+100;
    RedLUT[j]:=240;
    GreenLUT[j]:=240;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+110;
    RedLUT[j]:=250;
    GreenLUT[j]:=220;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+120;
    RedLUT[j]:=240;
    GreenLUT[j]:=200;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+130;
    RedLUT[j]:=240;
    GreenLUT[j]:=180;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+140;
    RedLUT[j]:=240;
    GreenLUT[j]:=140;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+150;
    RedLUT[j]:=240;
    GreenLUT[j]:=100;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+160;
    RedLUT[j]:=240;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
  for j:=171 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;

  UpdateLUT;
end;


macro 'INC strips 30 black [C]';
var
  i,j,l:integer;
begin
  for i:=1 to 30 do begin
    j:=i;
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+30;
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=208;
  end;
  for i:=1 to 10 do begin
    j:=i+40;
    RedLUT[j]:=0;
    GreenLUT[j]:=95;
    BlueLUT[j]:=240;
  end;
  for i:=1 to 10 do begin
    j:=i+50;
    RedLUT[j]:=0;
    GreenLUT[j]:=148;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+60;
    RedLUT[j]:=0;
    GreenLUT[j]:=198;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+70;
    RedLUT[j]:=10;
    GreenLUT[j]:=230;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+80;
    RedLUT[j]:=100;
    GreenLUT[j]:=240;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+90;
    RedLUT[j]:=198;
    GreenLUT[j]:=240;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+100;
    RedLUT[j]:=240;
    GreenLUT[j]:=240;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+110;
    RedLUT[j]:=250;
    GreenLUT[j]:=200;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+120;
    RedLUT[j]:=240;
    GreenLUT[j]:=140;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+130;
    RedLUT[j]:=240;
    GreenLUT[j]:=100;
    BlueLUT[j]:=0;
  end;
  for i:=1 to 10 do begin
    j:=i+140;
    RedLUT[j]:=240;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
  for j:=151 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;

  UpdateLUT;
end;


macro 'INC to CirPol [D]';
var
  i,j,l,diffo:integer;
begin
  for j:=1 to 90 do begin
  i:=round(2.5*j);
    RedLUT[j]:=i;
    GreenLUT[j]:=i;
    BlueLUT[j]:=i;
  end;
  for j:=1 to 90 do begin
  i:=181-j;
  l:=round(2.5*j);
    RedLUT[i]:=l;
    GreenLUT[i]:=l;
    BlueLUT[i]:=l;
  end;
  for j:=181 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;

  UpdateLUT;
end;

macro '(-' begin end;

macro 'crop reflect and stretch histo [V]';
var
  i,v,w,x,hlow,hup,n,mean,mode,min,max:integer;
  stretch: REAL;
  
begin

 SelectAll;
 ShowHistogram;
 Measure;
 GetResults(n,mean,mode,min,max);

hlow:=GetNumber('lower limit: ',min);
hup:=GetNumber('upper limit: ',max);

for i:=1 to hlow do begin
    v:= hlow-i+1;
    RedLUT[i]:=RedLUT[v];
    GreenLUT[i]:=GreenLUT[v];
    BlueLUT[i]:=BlueLUT[v];
end;

for i:=hlow to hup do begin
    w:= i-hlow+1;
    RedLUT[i]:=RedLUT[w];
    GreenLUT[i]:=GreenLUT[w];
    BlueLUT[i]:=BlueLUT[w];
end;

for i:=hup to 255 do begin
    x:= hup-(i-hup)-hlow;
    RedLUT[i]:=RedLUT[x];
    GreenLUT[i]:=GreenLUT[x];
    BlueLUT[i]:=BlueLUT[x];
end;

UpdateLUT;

stretch:=GetNumber('stretch to ?: ',254);
stretch:=stretch/(hup-hlow);

ApplyLUT;
MultiplyByConstant(stretch);

end;

macro 'sawtooth at limits [W]';
var
  i,v,w,x,hlow,hup,n,mean,mode,min,max:integer;
  stretch: REAL;
  
begin

 SelectAll;
 ShowHistogram;
 Measure;
 GetResults(n,mean,mode,min,max);

hlow:=GetNumber('lower limit: ',min);
hup:=GetNumber('upper limit: ',max);

for i:=1 to hlow do begin
    v:= (hup-hlow)-(hlow-i+1);
    RedLUT[i]:=RedLUT[v];
    GreenLUT[i]:=GreenLUT[v];
    BlueLUT[i]:=BlueLUT[v];
end;

for i:=hlow to hup do begin
    w:= i-hlow+1;
    RedLUT[i]:=RedLUT[w];
    GreenLUT[i]:=GreenLUT[w];
    BlueLUT[i]:=BlueLUT[w];
end;

for i:=hup to 255 do begin
    x:= i-hup+1;
    RedLUT[i]:=RedLUT[x];
    GreenLUT[i]:=GreenLUT[x];
    BlueLUT[i]:=BlueLUT[x];
end;

UpdateLUT;

stretch:=GetNumber('stretch to ?: ',254);
stretch:=stretch/(hup-hlow);

ApplyLUT;
MultiplyByConstant(stretch);

end;


macro 'FMAX to AZI [F]';
var
  i,v,w,x,hlow,hup,n,mean,mode,min,max:integer;
  stretch: REAL;
  
begin


for i:=1 to 45 do begin
    v:=i+135;
    RedLUT[i]:=RedLUT[v];
    GreenLUT[i]:=GreenLUT[v];
    BlueLUT[i]:=BlueLUT[v];
end;

for i:=46 to 180 do begin
    w:= i-45;
    RedLUT[i]:=RedLUT[w];
    GreenLUT[i]:=GreenLUT[w];
    BlueLUT[i]:=BlueLUT[w];
end;

UpdateLUT;

end;
macro '(-' begin end;


macro 'spectrum red-blue leave rest [1]';
var
i,j,l,min,max,sixth,coli:integer;
begin
min:= GetNumber('azimuth (lower limit): ',-30); 
max:= GetNumber('azimuth (upper limit): ',30);
sixth:=(max-min)/6;
coli:=255/sixth-2;
  for l:= 0 to sixth  do begin
		   j:= 180+min + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255;
     GreenLUT[j]:= 0;
     BlueLUT[j]:=  255-(l*coli);
  end;
  for l:= 0 to sixth do begin
		   j:= 180+min + sixth + l;
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255;
     GreenLUT[j]:= l*coli;
     BlueLUT[j]:=  0;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 2*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255-l*coli;
     GreenLUT[j]:= 255;
     BlueLUT[j]:=  0;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 3*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= 255;
     BlueLUT[j]:=  l*coli;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 4*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= 255-l*coli;
     BlueLUT[j]:=  255;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 5*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= 0;
     BlueLUT[j]:=  255-l*coli;
  end;

if min < 0 then begin
  for l:= max  to (180+min)  do begin
     RedLUT[l]:= 255-l;
     GreenLUT[l]:= 255-l;
     BlueLUT[l]:=255-l;
  end;
  for l:=181  to 255  do begin
     RedLUT[l]:= 255-l;
     GreenLUT[l]:= 255-l;
     BlueLUT[l]:=255-l;
  end;
end;

if min > 0 then begin
  for l:= 0  to min  do begin
     RedLUT[l]:= 255-l;
     GreenLUT[l]:= 255-l;
     BlueLUT[l]:= 255-l;
  end;
  for l:=max  to 255  do begin
     RedLUT[l]:= 255-l;
     GreenLUT[l]:= 255-l;
     BlueLUT[l]:= 255-l;
  end;
end;

 UpdateLUT;

end;




macro 'spectrum blue-red leave rest [2]';
var
i,j,l,min,max,sixth,coli, coliB,coliD:integer;
begin
min:= GetNumber('azimuth (lower limit): ',-30); 
max:= GetNumber('azimuth (upper limit): ',30);
sixth:=(max-min)/6;
coli:=255/sixth;
coliB:=180/sixth;
coliD:=75/sixth;
  for l:= 0 to sixth do begin
		   j:= 180+min + l;
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:=0;
     BlueLUT[j]:=   l*coli;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= l*coliB;
     BlueLUT[j]:=  255;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 2*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:=180+l*coliD;
     BlueLUT[j]:= 255-l*coli;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 3*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  l*coli;
     GreenLUT[j]:=255;
     BlueLUT[j]:= 0;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 4*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255;
     GreenLUT[j]:= 255-l*coli;
     BlueLUT[j]:=  0;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 5*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:= 255;
     GreenLUT[j]:= 0;
     BlueLUT[j]:= l*coli;
  end;

if min < 0 then begin
  for l:= max  to (180+min)  do begin
     RedLUT[l]:= 255-l;
     GreenLUT[l]:= 255-l;
     BlueLUT[l]:=255-l;
  end;
  for l:=181  to 255  do begin
     RedLUT[l]:= 255-l;
     GreenLUT[l]:= 255-l;
     BlueLUT[l]:=255-l;
  end;
end;

if min > 0 then begin
  for l:= 0  to min  do begin
     RedLUT[l]:= 255-l;
     GreenLUT[l]:= 255-l;
     BlueLUT[l]:= 255-l;
  end;
  for l:=max  to 255  do begin
     RedLUT[l]:= 255-l;
     GreenLUT[l]:= 255-l;
     BlueLUT[l]:= 255-l;
  end;
end;

 UpdateLUT;
end;


macro 'spectrum red-blue rest black [3]';
var
i,j,l,min,max,sixth,coli:integer;
begin
min:= GetNumber('azimuth (lower limit): ',-30); 
max:= GetNumber('azimuth (upper limit): ',30);
sixth:=(max-min)/6;
coli:=255/sixth-2;
  for l:= 0 to sixth  do begin
		   j:= 180+min + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255;
     GreenLUT[j]:= 0;
     BlueLUT[j]:=  255-(l*coli);
  end;
  for l:= 0 to sixth do begin
		   j:= 180+min + sixth + l;
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255;
     GreenLUT[j]:= l*coli;
     BlueLUT[j]:=  0;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 2*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255-l*coli;
     GreenLUT[j]:= 255;
     BlueLUT[j]:=  0;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 3*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= 255;
     BlueLUT[j]:=  l*coli;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 4*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= 255-l*coli;
     BlueLUT[j]:=  255;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 5*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= 0;
     BlueLUT[j]:=  255-l*coli;
  end;

if min < 0 then begin
  for l:= max  to (180+min)  do begin
     RedLUT[l]:= 0;
     GreenLUT[l]:= 0;
     BlueLUT[l]:=0;
  end;
  for l:=181  to 255  do begin
     RedLUT[l]:= 0;
     GreenLUT[l]:= 0;
     BlueLUT[l]:=0;
  end;
end;

if min > 0 then begin
  for l:= 0  to min  do begin
     RedLUT[l]:= 0;
     GreenLUT[l]:= 0;
     BlueLUT[l]:= 0;
  end;
  for l:=max  to 255  do begin
     RedLUT[l]:= 0;
     GreenLUT[l]:= 0;
     BlueLUT[l]:= 0;
  end;
end;

 UpdateLUT;

end;



macro 'spectrum blue-red rest black [4]';
var
i,j,l,min,max,sixth,coli, coliB,coliD:integer;
begin
min:= GetNumber('azimuth (lower limit): ',-30); 
max:= GetNumber('azimuth (upper limit): ',30);
sixth:=(max-min)/6;
coli:=255/sixth;
coliB:=180/sixth;
coliD:=75/sixth;
  for l:= 0 to sixth do begin
		   j:= 180+min + l;
     if j > 180 then j :=j-180;    
     RedLUT[j]:= 0;
     GreenLUT[j]:=0;
     BlueLUT[j]:=   l*coli;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= l*coliB;
     BlueLUT[j]:=  255;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 2*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:=180+l*coliD;
     BlueLUT[j]:= 255-l*coli;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 3*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  l*coli;
     GreenLUT[j]:= 255;
     BlueLUT[j]:= 0;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 4*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255;
     GreenLUT[j]:= 255-l*coli;
     BlueLUT[j]:=  0;
  end;
  for l:= 0 to sixth  do begin
		   j:= 180+min + 5*sixth + l;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:= 255- l*coli;
     GreenLUT[j]:= 0;
     BlueLUT[j]:=0;
  end;

if min < 0 then begin
  for l:= max  to (180+min)  do begin
     RedLUT[l]:= 0;
     GreenLUT[l]:= 0;
     BlueLUT[l]:=0;
  end;
  for l:=181  to 255  do begin
     RedLUT[l]:= 0;
     GreenLUT[l]:= 0;
     BlueLUT[l]:=0;
  end;
end;

if min > 0 then begin
  for l:= 0  to min  do begin
     RedLUT[l]:= 0;
     GreenLUT[l]:= 0;
     BlueLUT[l]:= 0;
  end;
  for l:=max  to 255  do begin
     RedLUT[l]:= 0;
     GreenLUT[l]:= 0;
     BlueLUT[l]:= 0;
  end;
end;

UpDateLUT;
end;


macro '(-' begin end;

macro 'misor LUT 45=black    [5]';
var
  i,j,l:integer;
begin
  for j:=1 to 46 do begin
    i:=j;
    RedLUT[i]:=255-5*i;
    GreenLUT[i]:=0;
    BlueLUT[i]:=255-5*i;
  end;
  for j:=1 to 45 do begin
    i:=j+46;
    RedLUT[i]:=0;
    GreenLUT[i]:=5*j;
    BlueLUT[i]:=i;
  end;
   for j:=92 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
 UpdateLUT;
end;

macro 'misor 0-30                   [6]';
var
 cone,i,j,l:integer;
 factor:integer;
begin
cone:=30;
cone:=GetNumber('cone width about reference direction ? ',cone);
factor:=254/cone;
   for j:=1 to cone do begin
   i:=j*factor;
    RedLUT[j]:=255-i;
    GreenLUT[j]:=255-i;
    BlueLUT[j]:=255-i;
  end;
   for j:=cone+1 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
 UpdateLUT;
end;


macro 'misor 30-60                 [7]';
var
 cone1,cone2,i,j,l:integer;
 factor:integer;
begin
cone1:=30;
cone2:=60;
cone1:=GetNumber('min. angle to reference direction ? ',cone1);
cone2:=GetNumber('max. angle to reference direction ? ',cone2);
factor:=254/cone2;
   for j:=1 to cone1 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
   for j:=cone1 to cone2 do begin
   i:=(j-cone1)*factor;
    RedLUT[j]:=255-i;
    GreenLUT[j]:=255-i;
    BlueLUT[j]:=255-i;
  end;
   for j:=cone2 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
 UpdateLUT;
end;

macro 'misor 60-90                 [8]';
var
 cone,i,j,l:integer;
 factor:integer;
begin
cone:=60;
cone:=GetNumber('minimal angle to reference direction ? ',cone);
factor:=254/90;
   for j:=1 to cone do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
   for j:=cone+1 to 90 do begin
   i:=(j-cone)*factor;
    RedLUT[j]:=255-i;
    GreenLUT[j]:=255-i;
    BlueLUT[j]:=255-i;
  end;
   for j:=91 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
 UpdateLUT;
end;



macro 'misor inverse spectrum [9]';
var
i,j,l,min,max,sixth,coli:integer;
begin
min:= 0; 
max:= 90;
sixth:=15;
coli:=255/sixth;
  for l:= 1 to sixth do begin
		   j:= 180+min + l -1;
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255;
     GreenLUT[j]:= (l-1)*coli;
     BlueLUT[j]:=  0;
  end;
  for l:= 1 to sixth  do begin
		   j:= 180+min + sixth + l -1;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  255-l*coli;
     GreenLUT[j]:= 255;
     BlueLUT[j]:=  0;
  end;
  for l:= 1 to sixth  do begin
		   j:= 180+min + 2*sixth + l -1;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= 255;
     BlueLUT[j]:=  l*coli;
  end;
  for l:= 1 to sixth  do begin
		   j:= 180+min + 3*sixth + l -1;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= 255-l*coli;
     BlueLUT[j]:=  255;
  end;
  for l:= 1 to sixth  do begin
		   j:= 180+min + 4*sixth + l -1;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  l*10;
     GreenLUT[j]:= 0;
     BlueLUT[j]:=  255;
  end;
  for l:= 1 to sixth  do begin
		   j:= 180+min + 5*sixth + l -1;    
     if j > 180 then j :=j-180;    
     RedLUT[j]:=  150-l*10;
     GreenLUT[j]:= 0;
     BlueLUT[j]:=  255-l*coli;
  end;
  for l:= 90 to 255  do begin
		   j:=l;    
     RedLUT[j]:=  0;
     GreenLUT[j]:= 0;
     BlueLUT[j]:=  0;
  end;
 UpdateLUT;
end;

macro '(-' begin end;

macro 'sawtooth 90 [S]';
var
  i,j,k,k2,m:integer;
begin
 for m:=1 to 90 do begin
 i:=m;
 j:=m+90;
 k:=2*m;
    RedLUT[i]:=255-k;
    GreenLUT[i]:=255-k;
    BlueLUT[i]:=255-k;

    RedLUT[j]:=255-k;
    GreenLUT[j]:=255-k;
    BlueLUT[j]:=255-k;
  end;

  for j:=181 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
 end;

UpdateLUT;
end;


macro 'rep sawtooth 90 []';
var
  i,j,k,k2,m:integer;
begin
 for m:=1 to 90 do begin
 i:=m;
 j:=m+90;
 k:=m;
    RedLUT[i]:=255-k;
    GreenLUT[i]:=255-k;
    BlueLUT[i]:=255-k;

    RedLUT[j]:=255-k;
    GreenLUT[j]:=255-k;
    BlueLUT[j]:=255-k;
  end;

  for m:=181 to 255 do begin
 j:=m;
 k:=m-180;
    RedLUT[j]:=255-k;
    GreenLUT[j]:=255-k;
    BlueLUT[j]:=255-k;
 end;

UpdateLUT;
end;


macro 'ramp 180 [T]';
var
  i,j,ii,jj,k,l,m,n:integer;
begin
 for m:=1 to 180 do begin
 i:=m;
 j:=m+180;
 
 k:=m;
    RedLUT[i]:=255-k;
    GreenLUT[i]:=255-k;
    BlueLUT[i]:=255-k;

  end;

  for j:=181 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
 end;

UpdateLUT;
end;



macro 'high edges yellow [U]';
var
i,j,l,minu,maxu,diffu,mino,maxo,diffo:integer;
factor: real;
begin
maxu:= GetNumber('Yellow above (grey value): ',60); 
factor:=254/maxu;
  for j:=1 to maxu do begin
    RedLUT[j]:=255-j*factor;
    GreenLUT[j]:=255-j*factor;
    BlueLUT[j]:=255-j*factor;
  end;
  for j:=maxu to 253 do begin
    RedLUT[j]:=255;
    GreenLUT[j]:=255;
    BlueLUT[j]:=0;
  end;
  for j:=253 to 255 do begin
    RedLUT[j]:=255;
    GreenLUT[j]:=255;
    BlueLUT[j]:=255;
  end;
  UpdateLUT;
end;



macro 'contrast low edges [E]';
var
i,j,l,minu,maxu,diffu,mino,maxo,diffo:integer;
factor: real;
begin
minu:= GetNumber('min. value: ',2); 
maxu:= GetNumber('max. value: ',10); 
diffu:=maxu-minu;
factor:=200/diffu;

  for j:=0 to minu do begin
    RedLUT[j]:=180;
    GreenLUT[j]:=0;
    BlueLUT[j]:=200;
  end;
  for j:=minu to maxu do begin
   l:=(j-minu)*factor;
    RedLUT[j]:=200-l;
    GreenLUT[j]:=55+l;
    BlueLUT[j]:=255;
  end;
  for j:=maxu to 90 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
  for j:=91 to 255 do begin
    RedLUT[j]:=0;
    GreenLUT[j]:=0;
    BlueLUT[j]:=0;
  end;
  UpdateLUT;
end;


macro '(-' begin end;


macro 'reset [R]';
BEGIN
SetPalette('Grayscale');
END;

